import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {
        Scanner scan= new Scanner(System.in);


            String str = scan.nextLine();
            int sum = Integer.MAX_VALUE;

            while(sum >= 10) {

                sum = 0;

                for(int i = 0; i < str.length(); i++) {
                    int num = str.charAt(i) - '0';
                    sum += num;
                }

                if(sum >= 10) {
                    str = String.valueOf(sum);
                }
            }

            System.out.println(sum);


    }
}
